import axios from 'axios';



// axios.defaults.headers.post['content-Type'] = 'appliction/x-www-form-urlencoded';
// 请求拦截  设置统一header
axios.interceptors.request.use(
    config => {
        if (localStorage.auth)
            config.headers.Authorization = "Bearer " + localStorage.auth
        return config
    },
    error => {
        return Promise.reject(error)
    })

// 响应拦截  401 token过期处理
axios.interceptors.response.use(response => {
    return response
}, error => {

    const { status } = error.response
    if (status == 401) {
        // 清除token
        localStorage.removeItem('auth')
    }

    return Promise.reject(error)
})

export default axios